package com.neuedu.web;

import com.neuedu.pojo.Userinfo;
import com.neuedu.service.UserinfoServiceImpl;
import com.neuedu.utils.MD5Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "UserRegServlet",urlPatterns = "/user/reg")
public class UserRegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String email = request.getParameter("email");
        String nickName = request.getParameter("username");
        String password = request.getParameter("pass");
        Date regTime = new Date();
        Userinfo userinfo =new Userinfo();
        userinfo.setEmail(email);
        userinfo.setNickname(nickName);
        userinfo.setPassword(MD5Utils.getPwd(password));
        userinfo.setRegtime(regTime);
        UserinfoServiceImpl userinfoService = new UserinfoServiceImpl();
        int  num = userinfoService.userReg(userinfo);
        if(num!=0){
            //跳转到登录页
            response.sendRedirect(request.getContextPath()+"/go/login");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
